.386
.model flat, stdcall
option casemap:none
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<外部依赖<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc 
includelib kernel32.lib 
include gdi32.inc
includelib gdi32.lib
include msvcrt.inc
includelib msvcrt.lib
include comdlg32.inc
includelib comdlg32.lib 
include winmm.inc
includelib winmm.lib

include players.inc
include Data.inc
include Game.inc
include Frame.inc
includelib Frame.lib

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<数据<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<路径>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
PATHSEG segment
    BGM_1_OPEN db 'OPEN music\bgm1.wav type MPEGVideo ALIAS MUSIC1', 0
    BGM_1_PLAY db 'PLAY MUSIC1 REPEAT', 0
    BGM_eat_PATH db 'music\eatVoice.wav', 0
    ;********************************************
    ;玩家
    IMG_player1_left_up_PATH db 'pics/p1lu.bmp',0;第一级左边
    IMG_player1_left_PATH db 'pics/p1l.bmp',0;
    IMG_player1_left_down_PATH db 'pics/p1ld.bmp',0

    IMG_player1_right_up_PATH db 'pics/p1ru.bmp',0;第一级右边
    IMG_player1_right_PATH db 'pics/p1r.bmp',0;
    IMG_player1_right_down_PATH db 'pics/p1rd.bmp',0

    IMG_player2_left_up_PATH db 'pics/p2lu.bmp',0;第二级左边
    IMG_player2_left_PATH db 'pics/p2l.bmp',0;
    IMG_player2_left_down_PATH db 'pics/p2ld.bmp',0

    IMG_player2_right_up_PATH db 'pics/p2ru.bmp',0;第二级右边
    IMG_player2_right_PATH db 'pics/p2r.bmp',0;
    IMG_player2_right_down_PATH db 'pics/p2rd.bmp',0

    IMG_player3_left_up_PATH db 'pics/p3lu.bmp',0;第三级左边
    IMG_player3_left_PATH db 'pics/p3l.bmp',0;
    IMG_player3_left_down_PATH db 'pics/p3ld.bmp',0

    IMG_player3_right_up_PATH db 'pics/p3ru.bmp',0;第三级右边
    IMG_player3_right_PATH db 'pics/p3r.bmp',0;
    IMG_player3_right_down_PATH db 'pics/p3rd.bmp',0

    ;AI
    IMG_AI1_left_up_PATH db 'pics/1lu.bmp',0;第一级左边
    IMG_AI1_left_PATH db 'pics/1l.bmp',0;
    IMG_AI1_left_down_PATH db 'pics/1ld.bmp',0

    IMG_AI1_right_up_PATH db 'pics/1ru.bmp',0;第一级右边
    IMG_AI1_right_PATH db 'pics/1r.bmp',0;
    IMG_AI1_right_down_PATH db 'pics/1rd.bmp',0

    IMG_AI2_left_up_PATH db 'pics/2lu.bmp',0;第二级左边
    IMG_AI2_left_PATH db 'pics/2l.bmp',0;
    IMG_AI2_left_down_PATH db 'pics/2ld.bmp',0

    IMG_AI2_right_up_PATH db 'pics/2ru.bmp',0;第二级右边
    IMG_AI2_right_PATH db 'pics/2r.bmp',0;
    IMG_AI2_right_down_PATH db 'pics/2rd.bmp',0

    IMG_AI3_left_up_PATH db 'pics/3lu.bmp',0;第三级左边
    IMG_AI3_left_PATH db 'pics/3l.bmp',0;
    IMG_AI3_left_down_PATH db 'pics/3ld.bmp',0

    IMG_AI3_right_up_PATH db 'pics/3ru.bmp',0;第三级右边
    IMG_AI3_right_PATH db 'pics/3r.bmp',0;
    IMG_AI3_right_down_PATH db 'pics/3rd.bmp',0

    ;UI背景
    IMG_Start_PATH db 'startpic.bmp', 0
    IMG_End_PATH db 'endpic.bmp', 0
    IMG_Sea_PATH db 'seaBottom.bmp',0
PATHSEG ENDS

IMGINFOSET segment
    IMG_Sea_INFO ImageInfoStruct <offset IMG_Sea_PATH, IMG_Sea_Height, IMG_Sea_Width>
    ;玩家
    IMG_player1_left_up_INFO ImageInfoStruct <offset IMG_player1_left_up_PATH, IMG_1_Height, IMG_1_Width>
    IMG_player1_left_INFO ImageInfoStruct <offset IMG_player1_left_PATH, IMG_1_Height, IMG_1_Width>
    IMG_player1_left_down_INFO ImageInfoStruct <offset IMG_player1_left_down_PATH, IMG_1_Height, IMG_1_Width>

    IMG_player1_right_up_INFO ImageInfoStruct <offset IMG_player1_right_up_PATH, IMG_1_Height, IMG_1_Width>
    IMG_player1_right_INFO ImageInfoStruct <offset IMG_player1_right_PATH, IMG_1_Height, IMG_1_Width>
    IMG_player1_right_down_INFO ImageInfoStruct <offset IMG_player1_right_down_PATH, IMG_1_Height, IMG_1_Width>

    IMG_player2_left_up_INFO ImageInfoStruct <offset IMG_player2_left_up_PATH, IMG_2_Height, IMG_2_Width>
    IMG_player2_left_INFO ImageInfoStruct <offset IMG_player2_left_PATH, IMG_2_Height, IMG_2_Width>
    IMG_player2_left_down_INFO ImageInfoStruct <offset IMG_player2_left_down_PATH, IMG_2_Height, IMG_2_Width>

    IMG_player2_right_up_INFO ImageInfoStruct <offset IMG_player2_right_up_PATH, IMG_2_Height, IMG_2_Width>
    IMG_player2_right_INFO ImageInfoStruct <offset IMG_player2_right_PATH, IMG_2_Height, IMG_2_Width>
    IMG_player2_right_down_INFO ImageInfoStruct <offset IMG_player2_right_down_PATH, IMG_2_Height, IMG_2_Width>

    IMG_player3_left_up_INFO ImageInfoStruct <offset IMG_player3_left_up_PATH, IMG_3_Height, IMG_3_Width>
    IMG_player3_left_INFO ImageInfoStruct <offset IMG_player3_left_PATH, IMG_3_Height, IMG_3_Width>
    IMG_player3_left_down_INFO ImageInfoStruct <offset IMG_player3_left_down_PATH, IMG_3_Height, IMG_3_Width>

    IMG_player3_right_up_INFO ImageInfoStruct <offset IMG_player3_right_up_PATH, IMG_3_Height, IMG_3_Width>
    IMG_player3_right_INFO ImageInfoStruct <offset IMG_player3_right_PATH, IMG_3_Height, IMG_3_Width>
    IMG_player3_right_down_INFO ImageInfoStruct <offset IMG_player3_right_down_PATH, IMG_3_Height, IMG_3_Width>

    ;AI
    IMG_AI1_left_up_INFO ImageInfoStruct <offset IMG_AI1_left_up_PATH, IMG_1_Height, IMG_1_Width>
    IMG_AI1_left_INFO ImageInfoStruct <offset IMG_AI1_left_PATH, IMG_1_Height, IMG_1_Width>
    IMG_AI1_left_down_INFO ImageInfoStruct <offset IMG_AI1_left_down_PATH, IMG_1_Height, IMG_1_Width>

    IMG_AI1_right_up_INFO ImageInfoStruct <offset IMG_AI1_right_up_PATH, IMG_1_Height, IMG_1_Width>
    IMG_AI1_right_INFO ImageInfoStruct <offset IMG_AI1_right_PATH, IMG_1_Height, IMG_1_Width>
    IMG_AI1_right_down_INFO ImageInfoStruct <offset IMG_AI1_right_down_PATH, IMG_1_Height, IMG_1_Width>

    IMG_AI2_left_up_INFO ImageInfoStruct <offset IMG_AI2_left_up_PATH, IMG_2_Height, IMG_2_Width>
    IMG_AI2_left_INFO ImageInfoStruct <offset IMG_AI2_left_PATH, IMG_2_Height, IMG_2_Width>
    IMG_AI2_left_down_INFO ImageInfoStruct <offset IMG_AI2_left_down_PATH, IMG_2_Height, IMG_2_Width>

    IMG_AI2_right_up_INFO ImageInfoStruct <offset IMG_AI2_right_up_PATH, IMG_2_Height, IMG_2_Width>
    IMG_AI2_right_INFO ImageInfoStruct <offset IMG_AI2_right_PATH, IMG_2_Height, IMG_2_Width>
    IMG_AI2_right_down_INFO ImageInfoStruct <offset IMG_AI2_right_down_PATH, IMG_2_Height, IMG_2_Width>

    IMG_AI3_left_up_INFO ImageInfoStruct <offset IMG_AI3_left_up_PATH, IMG_3_Height, IMG_3_Width>
    IMG_AI3_left_INFO ImageInfoStruct <offset IMG_AI3_left_PATH, IMG_3_Height, IMG_3_Width>
    IMG_AI3_left_down_INFO ImageInfoStruct <offset IMG_AI3_left_down_PATH, IMG_3_Height, IMG_3_Width>

    IMG_AI3_right_up_INFO ImageInfoStruct <offset IMG_AI3_right_up_PATH, IMG_3_Height, IMG_3_Width>
    IMG_AI3_right_INFO ImageInfoStruct <offset IMG_AI3_right_PATH, IMG_3_Height, IMG_3_Width>
    IMG_AI3_right_down_INFO ImageInfoStruct <offset IMG_AI3_right_down_PATH, IMG_3_Height, IMG_3_Width>

    ;UI背景
    IMG_Start_INFO ImageInfoStruct <offset IMG_Start_PATH, IMG_Start_Height, IMG_Start_Width>
    IMG_End_INFO ImageInfoStruct <offset IMG_End_PATH, IMG_End_Height, IMG_End_Width>
IMGINFOSET ENDS

IMGBITMAPHandle segment

    ;player
    IB_player1_right_up HBITMAP ? 
    IB_player1_right HBITMAP ?
    IB_player1_right_down HBITMAP ?
    IB_player1_left_up HBITMAP ? 
    IB_player1_left HBITMAP ?
    IB_player1_left_down HBITMAP ?

    IB_player2_right_up HBITMAP ? 
    IB_player2_right HBITMAP ?
    IB_player2_right_down HBITMAP ?
    IB_player2_left_up HBITMAP ? 
    IB_player2_left HBITMAP ?
    IB_player2_left_down HBITMAP ?

    IB_player3_right_up HBITMAP ? 
    IB_player3_right HBITMAP ?
    IB_player3_right_down HBITMAP ?
    IB_player3_left_up HBITMAP ? 
    IB_player3_left HBITMAP ?
    IB_player3_left_down HBITMAP ?

    ;AI
    IB_AI1_left_up HBITMAP ? 
    IB_AI1_left HBITMAP ?
    IB_AI1_left_down HBITMAP ?
    IB_AI1_right_up HBITMAP ? 
    IB_AI1_right HBITMAP ?
    IB_AI1_right_down HBITMAP ?

    IB_AI2_left_up HBITMAP ? 
    IB_AI2_left HBITMAP ?
    IB_AI2_left_down HBITMAP ?
    IB_AI2_right_up HBITMAP ? 
    IB_AI2_right HBITMAP ?
    IB_AI2_right_down HBITMAP ?

    IB_AI3_left_up HBITMAP ? 
    IB_AI3_left HBITMAP ?
    IB_AI3_left_down HBITMAP ?
    IB_AI3_right_up HBITMAP ? 
    IB_AI3_right HBITMAP ?
    IB_AI3_right_down HBITMAP ?

    ;UI背景
    IB_sea HBITMAP ? 
    StartPic HBITMAP ?
    EndPic HBITMAP ?
IMGBITMAPHandle ENDS

XiaoChengZhi segment
    MesDir sword 0                      ;1234上下左右
    PressFlag db 0                      ;1按下0未按下
    player playerFish <?>
    PlayerDirFlag DWORD 4 dup(0)        ;方向锁死
    bkqID DWORD ?
    player_picture_times dword 0
XiaoChengZhi ENDS

TianXingZhu segment
TianXingZhu ENDS

LiangYiDong segment
    UI_flag dword 0
    RePlay_flag dword 0
    EndUI1 db 'The final score is: ',0
    final_score db '0', 6 dup(0)
    num_cov db '%d',0
LiangYiDong ENDS

YuRuiKang segment
    rseed	DWORD  ?
YuRuiKang ENDS

FrameDataSEG segment
    hInstance HINSTANCE ?      
    GameName db 'Bigfisheatsmallfish',0
    mainHwnd HWND ?
    DeltaTime WORD 0
    windowClassName db 'GameMainWindow',0ah, 0
    windowName db 'Game', 0
FrameDataSEG ENDS

GlobalDataSEG segment
    ;AI全局数据
    AIList AIFish  100 dup(<99,99,99,99,99,99,99,99,99,99>)
    AISize equ SIZEOF AIFish
    del equ 99;删除后把数组里面的值赋值为99
    AIArraySize DWORD 100
    end_flag DWORD 0

    totalFishNum DWORD 6

    ;UI全局数据
    titleFont HFONT ?
    mainFont HFONT ?
    timer DWORD 0
    score dword 0
    szPlayerScore db 'Your Score: %d ', 0ah, 0
    szPlayerLevel db 'Level:  %d',0 
    szPlayerExp db 'Exp To Next Level:  %d', 0
    UI_playerScore db 30 dup (0)
    UI_Countdown db 10 dup(0)
    UI_playerExp db 23 dup(0)
    UI_playerLevel db 40 dup(0)
    curMaxExp DWORD ?
    szCountdown db '%d', 0ah, 0

    ;GameRuning Data
    bgID DWORD ?
    ;计时器
    IDT_MainTimer DWORD 1
    IDT_PlayerTimer DWORD 2
    IDT_PlayerWin DWORD 3
    IDT_CreatFish_Begin DWORD 100
    IDT_CreatFish_End DWORD 100
    IDT_ChangePlayer dword 2
GlobalDataSEG ENDS

FrameFunctionDeclaration segment 
    ;Debug
    sprintf PROTO C: PTR SBYTE, :PTR SBYTE, :vararg

    ;MainSence
    Initilizer PROTO hWnd:HWND
    Update PROTO hWnd:HWND 
    Rendering PROTO hWnd:HWND
    GameOver PROTO
    GameInit PROTO

    ;StartSence
    StartInitilizer PROTO  hWnd:HWND
    StartUpdate PROTO hWnd:HWND
    StartRendering PROTO hWnd:HWND

    ;EndSence
    EndInitilizer PROTO hWnd:HWND
    EndUpdate PROTO hWnd:HWND
    EndRendering PROTO hWnd:HWND

    ;场景切换
    Scene_switch PROTO  param:WPARAM, hWnd:HWND

    ;碰撞检测
    DealWithCollsionEvent PROTO obj1:DWORD, obj2:DWORD

    ;计时器处理
    TimerFactory PROTO timerID:DWORD

    ;WIN32接口
    WinMain PROTO hInst:HINSTANCE, hPrevInst:HINSTANCE, cmdLine:LPSTR, cmdShow:DWORD
    WndProc PROTO hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
FrameFunctionDeclaration ENDS

UserFunctionDeclaration segment
    CreateAIGameObject PROTO x:SWORD, y:SWORD, hImg:HBITMAP, imgW:DWORD, imgH:DWORD
    CreateWall PROTO x:dword, y:dword, w:dword, h:dword, colw:dword, colh:dword, wallKind : dword
    GetRandom PROTO range:DWORD
    CreateAIFish PROTO
    MoveAIFish PROTO id:DWORD
    AI_DealWithCollsion PROTO cID: DWORD,myID:DWORD
    Delete_ai PROTO id:DWORD
UserFunctionDeclaration ENDS

.code
    ;窗口创建
    WinMain PROC  hInst:HINSTANCE, hPrevInst:HINSTANCE, cmdLine:LPSTR, cmdShow:DWORD
    LOCAL wc:WNDCLASSEX
    LOCAL msg:MSG
    LOCAL hwnd:HWND

    ;设置窗口类属性
    mov wc.cbSize, SIZEOF WNDCLASSEX
    mov wc.style, CS_HREDRAW or CS_VREDRAW
    mov wc.lpfnWndProc, offset WndProc      
    mov wc.cbWndExtra, NULL
    push hInstance
    pop wc.hInstance
    mov wc.hbrBackground, COLOR_WINDOW+1
    mov wc.lpszMenuName, NULL
    mov wc.lpszClassName, offset windowClassName
    
    invoke LoadCursor, NULL, IDC_ARROW
    mov wc.hCursor, eax
    invoke RegisterClassEx, addr wc ;注册窗口类

    invoke CreateWindowEx,\
        NULL, \;option window styles
        offset windowClassName, \;window class
        offset windowName, \;window text
        WS_MAXIMIZE xor WS_OVERLAPPEDWINDOW xor WS_THICKFRAME, \;window style
        CW_USEDEFAULT, \;4个定位参数
        CW_USEDEFAULT, \              
        WindowWidth, \
        WindowHeight, \
        NULL, \;父窗口
        NULL, \;菜单/窗口标识符
        hInst, \;实例句柄
        NULL;额外应用数据

    mov hwnd, eax
    mov mainHwnd, eax

    invoke GameInit
    invoke ShowWindow, hwnd, cmdShow
    invoke UpdateWindow, hwnd

    .WHILE TRUE
        invoke GetMessage, ADDR msg, NULL, 0, 0
        .BREAK .IF(!eax)
        invoke TranslateMessage, ADDR msg   ;键盘输入有关
        invoke DispatchMessage, ADDR msg    ;通知操作系统调用相应的窗口过程
    .ENDW
    mov eax, msg.wParam
    ret
WinMain endp
    ;窗口过程（可编辑）
    WndProc PROC hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
    .IF uMsg == WM_DESTROY
        invoke FrameEnd
        invoke PostQuitMessage, NULL    ;生成退出消息
;****************************xcz begin***********************************************
    .ELSEIF (wParam==VK_UP&&uMsg==WM_KEYDOWN)||(wParam==VK_DOWN&&uMsg==WM_KEYDOWN)||(wParam==VK_LEFT&&uMsg==WM_KEYDOWN)||(wParam==VK_RIGHT&&uMsg==WM_KEYDOWN)
        invoke GetDir,uMsg,wParam
;****************************xcz end***********************************************
    .ELSEIF uMsg == WM_PAINT
        .IF UI_flag == 0
            invoke StartRendering,hWnd
        .ELSEIF UI_flag == 1
            invoke Rendering, hWnd
        .ELSEIF UI_flag == 2
            invoke EndRendering,hWnd
        .ENDIF
        ret
    .ELSEIF uMsg == WM_TIMER
        invoke TimerFactory, wParam
    .ELSEIF uMsg == WM_CHAR
        invoke Scene_switch,wParam,hWnd
    .ELSE
        invoke DefWindowProc,hWnd,uMsg,wParam,lParam 
        ret 
    .ENDIF
    xor eax, eax
    ret
WndProc endp

    ;场景切换
    Scene_switch PROC  param:WPARAM, hWnd:HWND
        .IF UI_flag == 0 
            .IF param == 58h || param == 78h
                mov totalFishNum,6
            .ELSEIF param == 43h || param == 63h
                mov totalFishNum,9
                ; invoke GameOver
                ; mov UI_flag, 2
                ; invoke EndInitilizer,hWnd
            .ELSEIF param == 56h || param == 76h
                mov totalFishNum,12
                mov UI_flag, 0
            .ENDIF
            invoke Initilizer,hWnd
            inc UI_flag
        .ENDIF

        .IF UI_flag == 2
            .IF param == 58h || param == 78h
                mov UI_flag,0
                invoke StartInitilizer,hWnd
            .ENDIF
        .ENDIF
    
        ret
    Scene_switch endp

    ;全局资源装载
    SetResource PROC stdcall
        ;位图装载：LoadBitMap(ImageInfoStruct, HBITHANDLE)
        invoke LoadBitMap, IMG_Sea_INFO, ADDR IB_sea
        invoke LoadBitMap, IMG_Start_INFO, ADDR StartPic
        invoke LoadBitMap, IMG_End_INFO, ADDR EndPic

        invoke LoadBitMap, IMG_player1_left_up_INFO , ADDR IB_player1_left_up
        invoke LoadBitMap, IMG_player1_left_INFO , ADDR IB_player1_left
        invoke LoadBitMap, IMG_player1_left_down_INFO , ADDR IB_player1_left_down
        invoke LoadBitMap, IMG_player1_right_up_INFO , ADDR IB_player1_right_up
        invoke LoadBitMap, IMG_player1_right_INFO , ADDR IB_player1_right
        invoke LoadBitMap, IMG_player1_right_down_INFO , ADDR IB_player1_right_down

        invoke LoadBitMap, IMG_player2_left_up_INFO , ADDR IB_player2_left_up
        invoke LoadBitMap, IMG_player2_left_INFO , ADDR IB_player2_left
        invoke LoadBitMap, IMG_player2_left_down_INFO , ADDR IB_player2_left_down
        invoke LoadBitMap, IMG_player2_right_up_INFO , ADDR IB_player2_right_up
        invoke LoadBitMap, IMG_player2_right_INFO , ADDR IB_player2_right
        invoke LoadBitMap, IMG_player2_right_down_INFO , ADDR IB_player2_right_down

        invoke LoadBitMap, IMG_player3_left_up_INFO , ADDR IB_player3_left_up
        invoke LoadBitMap, IMG_player3_left_INFO , ADDR IB_player3_left
        invoke LoadBitMap, IMG_player3_left_down_INFO , ADDR IB_player3_left_down
        invoke LoadBitMap, IMG_player3_right_up_INFO , ADDR IB_player3_right_up
        invoke LoadBitMap, IMG_player3_right_INFO , ADDR IB_player3_right
        invoke LoadBitMap, IMG_player3_right_down_INFO , ADDR IB_player3_right_down
        ;AI
        invoke LoadBitMap, IMG_AI1_left_up_INFO , ADDR IB_AI1_left_up
        invoke LoadBitMap, IMG_AI1_left_INFO , ADDR IB_AI1_left
        invoke LoadBitMap, IMG_AI1_left_down_INFO , ADDR IB_AI1_left_down
        invoke LoadBitMap, IMG_AI1_right_up_INFO , ADDR IB_AI1_right_up
        invoke LoadBitMap, IMG_AI1_right_INFO , ADDR IB_AI1_right
        invoke LoadBitMap, IMG_AI1_right_down_INFO , ADDR IB_AI1_right_down

        invoke LoadBitMap, IMG_AI2_left_up_INFO , ADDR IB_AI2_left_up
        invoke LoadBitMap, IMG_AI2_left_INFO , ADDR IB_AI2_left
        invoke LoadBitMap, IMG_AI2_left_down_INFO , ADDR IB_AI2_left_down
        invoke LoadBitMap, IMG_AI2_right_up_INFO , ADDR IB_AI2_right_up
        invoke LoadBitMap, IMG_AI2_right_INFO , ADDR IB_AI2_right
        invoke LoadBitMap, IMG_AI2_right_down_INFO , ADDR IB_AI2_right_down

        invoke LoadBitMap, IMG_AI3_left_up_INFO , ADDR IB_AI3_left_up
        invoke LoadBitMap, IMG_AI3_left_INFO , ADDR IB_AI3_left
        invoke LoadBitMap, IMG_AI3_left_down_INFO , ADDR IB_AI3_left_down
        invoke LoadBitMap, IMG_AI3_right_up_INFO , ADDR IB_AI3_right_up
        invoke LoadBitMap, IMG_AI3_right_INFO , ADDR IB_AI3_right
        invoke LoadBitMap, IMG_AI3_right_down_INFO , ADDR IB_AI3_right_down
        ret
    SetResource endp
    ;游戏结束（可编辑）
    GameOver PROC
        ;消除GameObject
        invoke sprintf, offset final_score, offset num_cov, score
        mov player.exp, 0;
        mov score, 0
        mov player.grade, 1;
        mov UI_flag, 2
        invoke FrameEnd
        invoke EndInitilizer, mainHwnd
        ret
    GameOver ENDP
    ;游戏初始化（可编辑）
    GameInit PROC
        invoke StartInitilizer, mainHwnd   ;初始化
        ret
    GameInit endp
    
    
    
    ;------------------------------场景1----------------------------
    ;起始场景初始化（可编辑）
    StartInitilizer PROC  hWnd:HWND
        LOCAL lgb_bg :GameObject
        LOCAL tmpCount : DWORD
        invoke FrameInit, hWnd, WindowWidth, WindowHeight
        ;mov eax,0
        .IF RePlay_flag == 0
            invoke SetResource
            mov RePlay_flag,1
        .ENDIF
        ;第一个创建对象必须是背景
        ;创建背景
        mov lgb_bg.posx, 0    ;起始位置x
        mov lgb_bg.posy, 0    ;起始位置y
        mov lgb_bg.kind, 0     ;对象类型
        push StartPic
        pop lgb_bg.himg  ;贴图句柄
        push IMG_Start_Width
        pop lgb_bg.imgw
        push IMG_Start_Height
        pop lgb_bg.imgh
        push COL_Sea_Width
        pop lgb_bg.collsionWidth
        push COL_Sea_Height
        pop lgb_bg.collsionHeight
        invoke AddGameObject, lgb_bg
        mov bgID, eax

        invoke CreateStandFont, -36, -18, 400, NULL
        mov titleFont, eax

        invoke GetDeltaTime ;用来初始化的，请勿删除
        invoke SetTimer, hWnd, IDT_MainTimer, REFRESHTIMEER, NULL
        ret
    StartInitilizer endp
    ;起始场景刷新（可编辑）
    StartUpdate PROC hWnd:HWND
        ;绘图部分
        invoke StartRendering,hWnd
        ret
    StartUpdate endp
    ;起始场景渲染
    StartRendering PROC hWnd:HWND
        LOCAL ps: PAINTSTRUCT
        LOCAL count : DWORD
        LOCAL objectsSize : DWORD

        invoke BeginPaint, hWnd, ADDR ps
        invoke BackGroundPaint, hWnd, 0
        mov ecx, 1
        mov count, ecx
        invoke GetGameObjectSize
        mov objectsSize, eax
        .WHILE ecx < objectsSize
            invoke GetGameObjectByIndex , ecx
            invoke GameObjectPaint, hWnd, [eax]
            inc count
            mov ecx, count
        .ENDW

        ;UI绘制部分
        RGB 0,0,255
        ; invoke UI_TextDraw, NULL, 300, 300, offset StartUI1, SIZEOF StartUI1,eax 
        ; invoke UI_TextDraw, NULL, 300, 400, offset StartUI2, SIZEOF StartUI2,eax

        invoke FinalPaint, hWnd
        invoke EndPaint, hWnd, ADDR ps
        ret
    StartRendering endp    
    ;----------------------------场景1结束--------------------------
    ;------------------------------场景2----------------------------
    Initilizer PROC  hWnd:HWND
        LOCAL lgb_bg :GameObject
        LOCAL tmpCount : DWORD
        LOCAL lbg_bkq : GameObject
        LOCAL ai :GameObject

        invoke FrameInit, hWnd, WindowWidth, WindowHeight
        invoke GetDeltaTime ;用来初始化的，请勿删除
        invoke SetTimer, hWnd, IDT_MainTimer, REFRESHTIMEER, NULL
        mov end_flag, 0


        invoke GetTime
        mov rseed,eax


        ;第一个创建对象必须是背景
        ;创建背景
        mov lgb_bg.posx, 0    ;起始位置x
        mov lgb_bg.posy, 0    ;起始位置y
        mov lgb_bg.kind, 0     ;对象类型
        push IB_sea
        pop lgb_bg.himg  ;贴图句柄
        push IMG_Sea_Width
        pop lgb_bg.imgw
        push IMG_Sea_Height
        pop lgb_bg.imgh
        push COL_Sea_Width
        pop lgb_bg.collsionWidth
        push COL_Sea_Height
        pop lgb_bg.collsionHeight
        invoke AddGameObject, lgb_bg
        mov bgID, eax


        ;****************************xcz begin***********************************************
        ;创建player
        mov lbg_bkq.posx, WindowWidth / 2     ;起始位置x
        mov lbg_bkq.posy, WindowHeight / 2    ;起始位置y
        mov lbg_bkq.kind, 5    ;对象类型
        push IB_player1_right_up
        pop lbg_bkq.himg  ;贴图句柄
        push IMG_1_Width
        pop lbg_bkq.imgw
        push IMG_1_Height
        pop lbg_bkq.imgh
        push IMG_1_Width
        pop lbg_bkq.collsionWidth
        push IMG_1_Height
        pop lbg_bkq.collsionHeight
        invoke AddGameObject, lbg_bkq
        mov bkqID, eax

        mov player.vx, 0
        mov player.vy, 0
        mov player.grade, 1
        mov player.exp, 0
        mov player.max_exp, play_maxexp_1
        mov curMaxExp, play_maxexp_1
        ;****************************xcz end***********************************************
        invoke SetTimer, hWnd, IDT_PlayerTimer, PlayerAnimFrame, NULL

        ;创建墙
        invoke CreateWall,WallLeftposX, WallLeftposY, WallLeftWidth, WallLeftHeight, WallLeftWidth, WallLeftHeight, WallLeftKind
        invoke CreateWall,WallRightposX, WallRightposY, WallRightWidth, WallRightHeight, WallRightWidth, WallRightHeight, WallRightKind
        invoke CreateWall,WallUpposX, WallUpposY, WallUpWidth, WallUpHeight, WallUpWidth, WallUpHeight, WallUpKind
        invoke CreateWall,WallDownposX, WallDownposY, WallDownWidth, WallDownHeight, WallDownWidth, WallDownHeight, WallDownKind


        ;AI列表初始化
         mov tmpCount, 6
         lea ebx, AIList
         mov ecx, tmpCount
         .WHILE ecx < AIArraySize
             push ecx
             pop [ebx]
             inc tmpCount
             add ebx,AISize
             mov ecx, tmpCount
         .ENDW

        ;创建AI
        ;1. CreateAIGameObject
        ;2. CreateFishObject
        xor ecx, ecx
        .WHILE ecx < totalFishNum
            push ecx
            invoke CreateAIFish
            pop ecx
            inc ecx
        .ENDW
        mov score, 0
        invoke CreateStandFont, -36, -18, 400, NULL
        mov titleFont, eax
        invoke CreateStandFont, -72, -36, 900, NULL
        mov mainFont, eax
        mov eax, SND_ASYNC
        OR eax, SND_LOOP
        invoke mciSendString, offset BGM_1_OPEN, NULL, 0, 0
        invoke mciSendString, offset BGM_1_PLAY, NULL, 0, NULL
        ret
    Initilizer endp
    Update PROC hWnd:HWND
        LOCAL aiOffset : DWORD
        LOCAL count : DWORD

        invoke GetDeltaTime
        mov DeltaTime, ax
        ;**************************xcz begin*********************************************
        invoke ChangeV, MesDir
        ;.if(PressFlag==1)
        ;    invoke ChangeV,MesDir
        ;.endif
        mov PressFlag,0
        invoke UpdatePlayerPlace,DeltaTime
        ;**************************xcz end***********************************************

        ;循环遍历AI数组，非del情况下，调用move
        mov ebx, offset AIList
        mov aiOffset, ebx
        mov count, 0
        mov ecx, count
        .WHILE ecx < AIArraySize
            mov ebx, aiOffset
            mov eax, [ebx+4]
            .IF eax != del
                invoke MoveAIFish, [ebx]
            .ENDIF
            mov eax, aiOffset
            add eax, AISize
            mov aiOffset, eax
            inc count
            mov ecx, count
        .ENDW

        .IF end_flag == 1
            mov eax, timer
            mov bx, DeltaTime
            movzx ebx, bx
            sub eax, ebx
            mov timer, eax
        .ENDIF

        invoke CollisionDetectAllGameObjects
        invoke RefreshObjectList

        ;绘图部分
        invoke Rendering,hWnd
        ret
Update endp
    Rendering PROC hWnd:HWND
        LOCAL ps: PAINTSTRUCT
        LOCAL count : DWORD
        LOCAL objectsSize : DWORD

        invoke BeginPaint, hWnd, ADDR ps
        invoke BackGroundPaint, hWnd, 0
        mov ecx, 1
        mov count, ecx
        invoke GetGameObjectSize
        mov objectsSize, eax
        .WHILE ecx < objectsSize
            invoke GetGameObjectByIndex , ecx
            invoke GameObjectPaint, hWnd, [eax]
            inc count
            mov ecx, count
        .ENDW

        ;UI绘制部分

        invoke sprintf, offset UI_playerLevel, offset szPlayerLevel, player.grade
        RGB 100, 255, 30
        invoke UI_TextDraw, titleFont, 30, 60, offset UI_playerLevel, SIZEOF UI_playerLevel, eax 

        mov eax, curMaxExp 
        sub ax, player.exp

        invoke sprintf, offset UI_playerExp, offset szPlayerExp, eax
        mov ebx, offset UI_playerExp
        mov eax, 0
        add ebx, SIZEOF UI_playerExp
        mov [ebx + SIZEOF UI_playerExp], eax

        RGB 100, 255, 30
        invoke UI_TextDraw, titleFont, 30, 100, offset UI_playerExp, SIZEOF UI_playerExp, eax 


        invoke sprintf, offset UI_playerScore, offset szPlayerScore, score
        .IF end_flag == 1
            mov eax, timer
            cwd
            mov cx, 1000
            div cx
            invoke sprintf, offset UI_Countdown, offset szCountdown, eax
            RGB 123, 30, 255
            invoke UI_TextDraw, mainFont, WindowWidth / 2, WindowHeight / 2, offset UI_Countdown, SIZEOF UI_Countdown, eax 
        .ENDIF

        RGB 255, 30, 10
        invoke UI_TextDraw, titleFont, 30, 20, offset UI_playerScore, SIZEOF UI_playerScore, eax 

        invoke FinalPaint, hWnd
        invoke EndPaint, hWnd, ADDR ps
        ret
Rendering endp
    ;----------------------------场景2结束--------------------------
    ;------------------------------场景3----------------------------
    EndInitilizer PROC  hWnd:HWND
        LOCAL lgb_bg :GameObject
        LOCAL tmpCount : DWORD

        
        invoke FrameInit, hWnd, WindowWidth, WindowHeight


        ;第一个创建对象必须是背景
        ;创建背景
        mov lgb_bg.posx, 0    ;起始位置x
        mov lgb_bg.posy, 0    ;起始位置y
        mov lgb_bg.kind, 0     ;对象类型
        push EndPic
        pop lgb_bg.himg  ;贴图句柄
        push IMG_End_Width
        pop lgb_bg.imgw
        push IMG_End_Height
        pop lgb_bg.imgh
        push COL_Sea_Width
        pop lgb_bg.collsionWidth
        push COL_Sea_Height
        pop lgb_bg.collsionHeight
        invoke AddGameObject, lgb_bg
        mov bgID, eax

        invoke CreateStandFont, -36, -18, 600, NULL
        mov titleFont, eax

        invoke GetDeltaTime ;用来初始化的，请勿删除
        invoke SetTimer, hWnd, IDT_MainTimer, REFRESHTIMEER, NULL
        ret
    EndInitilizer endp
    EndUpdate PROC hWnd:HWND
        ;绘图部分
        invoke EndRendering,hWnd
        ret
    EndUpdate endp
    EndRendering PROC hWnd:HWND
        LOCAL ps: PAINTSTRUCT
        LOCAL count : DWORD
        LOCAL objectsSize : DWORD

        invoke BeginPaint, hWnd, ADDR ps
        invoke BackGroundPaint, hWnd, 0
        mov ecx, 1
        mov count, ecx
        invoke GetGameObjectSize
        mov objectsSize, eax
        .WHILE ecx < objectsSize
            invoke GetGameObjectByIndex , ecx
            invoke GameObjectPaint, hWnd, [eax]
            inc count
            mov ecx, count
        .ENDW

        ;UI绘制部分
        RGB 0,0,255
        invoke UI_TextDraw, titleFont, 500, 100, offset EndUI1, SIZEOF EndUI1,eax 
        invoke UI_TextDraw, titleFont, 650, 200, offset final_score, SIZEOF final_score,eax

        invoke FinalPaint, hWnd
        invoke EndPaint, hWnd, ADDR ps
        ret
    EndRendering endp
    ;----------------------------场景3结束--------------------------
    ;--------------------------计时器处理中枢------------------------
    TimerFactory PROC timerID : DWORD
        mov eax, timerID
        .IF eax == IDT_MainTimer
            .IF UI_flag == 0
                invoke StartUpdate, mainHwnd
            .ELSEIF UI_flag == 1
                invoke Update,  mainHwnd
            .ELSEIF UI_flag == 2
                invoke EndUpdate, mainHwnd
            .ENDIF
        .ELSEIF eax == IDT_CreatFish_End && UI_flag == 1
            invoke CreateAIFish
            invoke KillTimer,mainHwnd,IDT_CreatFish_End
            inc IDT_CreatFish_End
        .ELSEIF eax == IDT_PlayerWin
            invoke GameOver
            mov UI_flag, 2
            invoke KillTimer, mainHwnd, IDT_PlayerWin
            invoke EndInitilizer,mainHwnd
            
        .ENDIF
        ;-----------------------------------playerChange---------------------------
        .IF eax == IDT_PlayerTimer
            invoke ChangePlayerPictureDir
        .ENDIF
        ;----------------------------------end---------------------------------------
            ret
    TimerFactory endp
    ;---------------------------碰撞处理器--------------------------
    DealWithCollsionEvent PROC obj1:DWORD, obj2:DWORD
        mov eax, obj1
        .IF eax == bkqID
            invoke Player_DealWithCollsion, obj2, obj1
        .ELSE
            invoke GetGameObject, obj1
            mov eax, [eax+4]
            .IF eax == AIKind
                invoke AI_DealWithCollsion, obj2, obj1
            .ENDIF
            invoke GetGameObject, obj2
            mov eax, [eax+4]
            .IF eax == AIKind
                invoke AI_DealWithCollsion, obj1, obj2
            .ENDIF
        .ENDIF
        ret
    DealWithCollsionEvent endp
  


;----------------------------------------------GameFunction(AI)---------------------------------------
;创建墙
CreateWall PROC x:dword, y:dword, w:dword, h:dword, colw:dword, colh:dword, wallKind : dword
    LOCAL wall:GameObject

    push x
    pop wall.posx
    push y
    pop wall.posy
    push w
    pop wall.imgw
    push h
    pop wall.imgh
    push wallKind
    pop wall.kind
    push NULL
    pop wall.himg
    push colw
    pop wall.collsionWidth
    push colh
    pop wall.collsionHeight
    invoke AddGameObject,wall
    ret
CreateWall endp
;获取AI鱼
GetAIObject PROC uses ebx id:DWORD
    LOCAL sizeOFai :DWORD
    mov eax, AISize
    mov sizeOFai, eax
    lea ebx, AIList

    mov ecx, 0
    .WHILE  ecx < AIArraySize
        mov eax,  [ebx]
        .Break .IF (eax == id)
        add ebx, sizeOFai
        inc ecx
    .ENDW
    .IF ecx < AIArraySize
        mov eax, ebx
        ret
    .ELSE
        mov eax, NULL
        ret
    .ENDIF
GetAIObject endp

;设置AI鱼数据，实现绑定需手动
SetAIInfo  PROC uses ebx velocityX:SWORD, velocityY:SWORD, id:DWORD, level:DWORD, changetime:DWORD, movetime:DWORD, curtime:DWORD, exp:DWORD, bantime:DWORD, avoidtime:DWORD, aikind:DWORD
    invoke GetAIObject, id
    .IF eax == NULL
        ret
    .ENDIF
    mov ebx, eax    ;对应对象起始位置
    push velocityX
    pop [ebx+8]
    push velocityY
    pop [ebx+10]
    push level
    pop [ebx+4]
    push changetime
    pop [ebx+12]
    push movetime
    pop [ebx+16]
    push curtime
    pop [ebx+20]
    push exp
    pop [ebx+24]
    push bantime
    pop [ebx+28]
    push avoidtime
    pop [ebx+32]
    push aikind
    pop [ebx+36]

    ret
SetAIInfo endp

;删除游戏对象
Delete_ai PROC id:DWORD
    invoke GetAIObject, id
    .IF eax == NULL
        ret
    .ENDIF
    mov ebx, eax    ;对应对象起始位置
    push del
    pop DWORD PTR [ebx+4]
    push del
    pop WORD PTR [ebx+8]
    push del
    pop WORD PTR [ebx+10]
    push del
    pop DWORD PTR [ebx+12]
    push del
    pop DWORD PTR [ebx+16]
    push del
    pop DWORD PTR [ebx+20]
    push del
    pop DWORD PTR [ebx+24]
    push del
    pop DWORD PTR [ebx+28]
    push del
    pop DWORD PTR [ebx+32]
    push del
    pop DWORD PTR [ebx+36]

    invoke DeleteGameObject, id
    ret

Delete_ai endp

;获得随机数
GetRandom proc uses ecx edx,range:DWORD
    
    inc rseed
    mov eax, rseed
	mov ecx, 23
	mul ecx
	add eax, 7
	and eax, 0FFFFFFFFh
	ror eax, 1
	xor eax, rseed
	mov rseed, eax
	mov ecx, range
	xor edx, edx
	div ecx
	mov eax, edx
	ret

GetRandom endp

;创建AI鱼
CreateAIFish proc  ;返回id
    LOCAL ai_fish :GameObject
    LOCAL id: DWORD
    LOCAL level :DWORD
    
    LOCAL curtime : DWORD
    LOCAL movetime:DWORD 
    LOCAL bantime :DWORD
    LOCAL avoidtime :DWORD
    LOCAL velocityX: SWORD
    LOCAL velocityY: SWORD
    LOCAL changetime: DWORD
    LOCAL exp : DWORD
    LOCAL w : DWORD
    LOCAL aikindFlag :DWORD 
    LOCAL aikind :DWORD
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    invoke GetRandom,2  ;取随机数0，1
    mov w,IMG_Sea_Width ;将界面宽度导入 
    mul w  ;eax与之相乘
    mov ai_fish.posx, eax;起始位置x 随机为两侧
    
    invoke GetRandom,500  ;因为高为768 所以 设置高度为100-600
    add eax,140
    mov ai_fish.posy,eax ;起始位置y 对于ai来说起始高度范围为140-640

    ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
     mov ai_fish.kind,AIKind

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    .if ai_fish.posx == 0
       mov aikindFlag,0 ;对象类型FLAG  AIkind分为两类 一类是出生在左侧的鱼向右侧游，一类是在右侧的鱼往左侧游
    .else 
       mov aikindFlag,1
    .endif
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 


    invoke GetRandom,3 ;！！此处需修改 等级跟游戏设定一致 此处假定3级
    ADD eax,1
    mov level, eax    ;此处ai 范围为 1-3
    .IF ax > player.grade
      ;检查场内是否存在比玩家低的鱼
      mov ebx, offset AIList
      mov ecx, 0
      .WHILE ecx < AIArraySize
        mov eax, [ebx+4]
        .BREAK .IF ax <= player.grade
        inc ecx
      .ENDW
    .ENDIF

    .IF ecx == AIArraySize
        mov ax, player.grade
        movsx eax, ax
        mov level, eax
    .ENDIF
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

.if level == 1
    .if aikindFlag == 0 ;1级向右游 使用 3 4 图 初始为3图
       push IB_AI1_right_up
       pop ai_fish.himg  ;贴图句柄 此处需要根据bird的等级来选择相应的贴图, !!!!此处需修改 ！！！！！！
       push IMG_1_Width
       pop ai_fish.imgw
       push IMG_1_Height
       pop ai_fish.imgh

        ;zyyadd
       push COL_Fish_Width 
       pop ai_fish.collsionWidth
       push COL_Fish_Height
       pop ai_fish.collsionHeight
        ;zyyend
    .elseif aikindFlag == 1 ;1级向左游 使用 1 2图 初始为1图

       push IB_AI1_left_up
       pop ai_fish.himg  ;贴图句柄 此处需要根据bird的等级来选择相应的贴图, !!!!此处需修改 ！！！！！！
       push IMG_1_Width
       pop ai_fish.imgw
       push IMG_1_Height
       pop ai_fish.imgh

        ;zyyadd
       push COL_Fish_Width 
       pop ai_fish.collsionWidth
       push COL_Fish_Height 
       pop ai_fish.collsionHeight

    .endif
.elseif level == 2
    .if aikindFlag == 0 ;1级向右游 使用 3 4 图 初始为3图
       push IB_AI2_right_up
       pop ai_fish.himg  ;贴图句柄 此处需要根据bird的等级来选择相应的贴图, !!!!此处需修改 ！！！！！！
       push IMG_2_Width
       pop ai_fish.imgw
       push IMG_2_Height
       pop ai_fish.imgh

        ;zyyadd
       push COL_Fish_Width 
       pop ai_fish.collsionWidth
       push COL_Fish_Height
       pop ai_fish.collsionHeight
        ;zyyend
    .elseif aikindFlag == 1 ;1级向左游 使用 1 2图 初始为1图

       push IB_AI2_left_up
       pop ai_fish.himg  ;贴图句柄 此处需要根据bird的等级来选择相应的贴图, !!!!此处需修改 ！！！！！！
       push IMG_2_Width
       pop ai_fish.imgw
       push IMG_2_Height
       pop ai_fish.imgh

        ;zyyadd
       push COL_Fish_Width 
       pop ai_fish.collsionWidth
       push COL_Fish_Height 
       pop ai_fish.collsionHeight

    .endif
.elseif level==3
    .if aikindFlag == 0 ;1级向右游 使用 3 4 图 初始为3图
       push IB_AI3_right_up
       pop ai_fish.himg  ;贴图句柄 此处需要根据bird的等级来选择相应的贴图, !!!!此处需修改 ！！！！！！
       push IMG_3_Width
       pop ai_fish.imgw
       push IMG_3_Height
       pop ai_fish.imgh

        ;zyyadd
       push COL_Fish_Width 
       pop ai_fish.collsionWidth
       push COL_Fish_Height
       pop ai_fish.collsionHeight
        ;zyyend
    .elseif aikindFlag == 1 ;1级向左游 使用 1 2图 初始为1图

       push IB_AI3_left_up
       pop ai_fish.himg  ;贴图句柄 此处需要根据bird的等级来选择相应的贴图, !!!!此处需修改 ！！！！！！
       push IMG_3_Width
       pop ai_fish.imgw
       push IMG_3_Height
       pop ai_fish.imgh

        ;zyyadd
       push COL_Fish_Width 
       pop ai_fish.collsionWidth
       push COL_Fish_Height
       pop ai_fish.collsionHeight
    .endif
.endif

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>创建ganmeobjext对象   在这里已创建aifish结构
      invoke AddGameObject, ai_fish
      mov id, eax 
;>>>>>>......>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    ;根据等级设定初始速度 与经验
    .if level == 1
        mov velocityX, ai_fish_speed0 ;!!此处需修改 速度跟游戏设定一致 此处假定ai_fish_speed0，未定义
        invoke GetRandom, 2*ai_fish_speed0 ;在y方向上速度的随机变化范围为 -speed0 - speed0
        mov velocityY,ax
        sub velocityY,ai_fish_speed0
        mov exp, ai_fish_exp1 ;！！此处需修改 此处假定AIFish_exp0，未定义
    .elseif level == 2
        mov velocityX,ai_fish_speed1 ;!!此处需修改 速度跟游戏设定一致 此处假定ai_fish_speed0，未定义
        invoke GetRandom,2*ai_fish_speed1;在y方向上速度的随机变化范围为 -speed1 - speed1
        mov velocityY,ax
        sub velocityY,ai_fish_speed1
        mov exp,  ai_fish_exp2 ;！！此处需修改 此处假定AIFish_exp0，未定义
    .elseif level == 3
        mov velocityX,ai_fish_speed2 ;!!此处需修改 速度跟游戏设定一致 此处假定ai_fish_speed0，未定义
        invoke GetRandom,2*ai_fish_speed2;在y方向上速度的随机变化范围为 -speed1 - speed1
        mov velocityY,ax
        sub velocityY,ai_fish_speed2
        mov exp,  ai_fish_exp3;！！此处需修改 此处假定AIFish_exp2，未定义
    .endif

     .if aikindFlag == 1;从右向走 x速度为负数
           mov aikind,ai_fish_kind6
           neg velocityX
    .elseif aikindFlag == 0
          mov aikind,ai_fish_kind5

       .endif
    
    
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    ;设定现在时间
    invoke GetTime  
    mov curtime,eax ;此函数会更新现在创造ai鱼的时间CURTIME
    mov avoidtime,eax  ;记录avoidtime 出生时间
    mov changetime,eax  ;记录改变姿态（贴图）时刻
    mov movetime,eax  ;记录改变方向时刻
    mov bantime, 0 ;记录 撞上下墙后 速度方向锁定时刻
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    invoke SetAIInfo ,velocityX,velocityY,id,level,changetime,movetime,curtime,exp,bantime,avoidtime,aikind
    mov eax,id
    ret
CreateAIFish endp
;移动AI鱼
MoveAIFish proc id:DWORD  ;此函数对于每个鱼 在每次刷新时都要遍历执行
    LOCAL disX : SDWORD
    LOCAL disY : SDWORD

    LOCAL level :DWORD
    LOCAL aikind: DWORD
    LOCAL curtime : DWORD ;
    LOCAL movetime:DWORD  ;上一次随即改变速度的时刻
    LOCAL velocityX: SWORD
    LOCAL velocityY: SWORD
    LOCAL changetime:DWORD ;上一次改变姿态(动画）的时刻
    LOCAL himg: HBITMAP
    LOCAL gameobjectPTR : DWORD
    LOCAL AIPTR : DWORD
    LOCAL bantime:DWORD ;禁止上游或下游的时间
    local avoidtime :DWORD ; 在出生时避免碰撞检测的时间

    LOCAL time:DWORD
    LOCAL deltatime:WORD

    invoke GetGameObject, id    
    .IF eax == NULL
        ret
    .ENDIF

    push [eax+16]
    pop himg
    invoke GetAIObject, id
    push [eax+4]
    pop level
    push [eax+8]
    pop velocityX
    push [eax+10]
    pop velocityY
    push [eax+12]
    pop changetime
    push [eax+16]
    pop movetime
    push [eax+20]
    pop curtime
    push [eax+28]
    pop bantime
    push [eax+32]
    pop avoidtime
    push [eax+36]
    pop aikind
  
    invoke GetTime  
    mov time,eax
    sub eax,curtime
    mov deltatime,ax ;delta储存上一次刷新到现在的时间

   
    
    invoke GetAIObject,id
    push time
    pop  [eax+20]
     ;更新curtime
    ;/////////////////////////////////////////////////////////////////////在一定时间后随机更改y方向速度
    mov eax,time
    sub eax,movetime
    .if eax > 3000 ;!!此处改变方向间隔可以修改 ！！小于一定时间间隔不改变速度  只有在大于3s后才会随机改变y方向速度
         .if level == 1
           invoke GetRandom,2*ai_fish_speed0 ;！！此处需修改！！在y方向上速度的随机变化范围为 -AIFish_speed0 到+AIfsih——speed0
           mov velocityY,ax
           sub velocityY,ai_fish_speed0
        .elseif level== 2
            invoke GetRandom,2*ai_fish_speed1 ;！！此处需修改！！在y方向上速度的随机变化范围为
            mov velocityY,ax
            sub  velocityY,ai_fish_speed1
        .elseif level == 3
            invoke GetRandom,2*ai_fish_speed2 ;！！此处需修改！！在y方向上速度的随机变化范围为
            mov velocityY,ax
           sub  velocityY,ai_fish_speed2
        .endif
        invoke GetAIObject,id
        ;更改存储此时aifish数据结构的y速度数据 以方便之后小于3s时按照之前速度匀速行进   
        push time
        pop [eax+16] ;更新movetime 使得movetime上一次随即改变速度的时刻改变为此时
    .endif
 ;//////////////////////////////////////////////////////////////////////////// 此部分处理当无敌时间失效后的相应操作：更改kind的值 来使下一次move时
    mov eax,time
    sub eax,avoidtime
    .if eax > 2000  ;出生无敌时间为2s 不受墙的阻碍 否则更改ai鱼类型
      .if aikind == ai_fish_kind5
        invoke GetAIObject,id
        push ai_fish_kind1
        pop [eax+36]
      .elseif aikind == ai_fish_kind6
        invoke GetAIObject,id
        push ai_fish_kind2
        pop [eax+36]
      .endif
    .endif
 ;////////////////////////////////////////////////////////////////////////////
    mov eax,time
    sub eax, changetime ;changetime在fish对象中作为属性存储 是上一次改变姿态的时间
    .if eax > 1000 ;0.4秒更新一次姿态  此处需修改！！！！图像并未设置完！！！
      mov eax, himg
.if level== 1
            .if eax == IB_AI1_left_up   ;贴图句柄1
                invoke  ChangeGameObjectImg, id, IB_AI1_left,IMG_1_Width, IMG_1_Height;贴图句柄2此处需修改！！！！图像并未设置完！！！
            .elseif eax == IB_AI1_left  ;贴图句柄2
                invoke  ChangeGameObjectImg, id, IB_AI1_left_down,IMG_1_Width, IMG_1_Height;贴图句柄2此处需修改！！！！图像并未设置完！！！
            .elseif eax == IB_AI1_left_down  ;贴图句柄2
                invoke  ChangeGameObjectImg, id, IB_AI1_left_up,IMG_1_Width, IMG_1_Height;贴图句柄2此处需修改！！！！图像并未设置完！！！
            .elseif eax == IB_AI1_right_up   ;贴图句柄3
                invoke  ChangeGameObjectImg, id, IB_AI1_right,IMG_1_Width, IMG_1_Height;贴图句柄2此处需修改！！！！图像并未设置完！！！
            .elseif eax == IB_AI1_right   ;贴图句柄4
                invoke  ChangeGameObjectImg, id, IB_AI1_right_down,IMG_1_Width, IMG_1_Height;贴图句柄2此处需修改！！！！图像并未设置完！！！
            .elseif eax == IB_AI1_right_down  ;贴图句柄2
                invoke  ChangeGameObjectImg, id, IB_AI1_right_down,IMG_1_Width, IMG_1_Height;贴图句柄2此处需修改！！！！图像并未设置完！！！
            .endif
        .elseif level == 2
           .if eax == IB_AI2_left_up   ;贴图句柄1
                invoke  ChangeGameObjectImg, id, IB_AI2_left,IMG_2_Width, IMG_2_Height;贴图句柄2此处需修改！！！！图像并未设置完！！！
            .elseif eax == IB_AI2_left  ;贴图句柄2
                invoke  ChangeGameObjectImg, id, IB_AI2_left_down,IMG_2_Width, IMG_2_Height;贴图句柄2此处需修改！！！！图像并未设置完！！！
            .elseif eax == IB_AI2_left_down  ;贴图句柄2
                invoke  ChangeGameObjectImg, id, IB_AI2_left_up,IMG_2_Width, IMG_2_Height;贴图句柄2此处需修改！！！！图像并未设置完！！！
            .elseif eax == IB_AI2_right_up   ;贴图句柄3
                invoke  ChangeGameObjectImg, id, IB_AI2_right,IMG_2_Width, IMG_2_Height;贴图句柄2此处需修改！！！！图像并未设置完！！！
            .elseif eax == IB_AI2_right   ;贴图句柄4
                invoke  ChangeGameObjectImg, id, IB_AI2_right_down,IMG_2_Width, IMG_2_Height;贴图句柄2此处需修改！！！！图像并未设置完！！！
            .elseif eax == IB_AI2_right_down  ;贴图句柄2
                invoke  ChangeGameObjectImg, id, IB_AI2_right_down,IMG_2_Width, IMG_2_Height;贴图句柄2此处需修改！！！！图像并未设置完！！！
            .endif
         .elseif level == 3
            .if eax == IB_AI3_left_up   ;贴图句柄1
                invoke  ChangeGameObjectImg, id, IB_AI3_left,IMG_3_Width, IMG_3_Height;贴图句柄2此处需修改！！！！图像并未设置完！！！
            .elseif eax == IB_AI3_left  ;贴图句柄2
                invoke  ChangeGameObjectImg, id, IB_AI3_left_down,IMG_3_Width, IMG_3_Height;贴图句柄2此处需修改！！！！图像并未设置完！！！
            .elseif eax == IB_AI3_left_down  ;贴图句柄2
                invoke  ChangeGameObjectImg, id, IB_AI3_left_up,IMG_3_Width, IMG_3_Height;贴图句柄2此处需修改！！！！图像并未设置完！！！
            .elseif eax == IB_AI3_right_up   ;贴图句柄3
                invoke  ChangeGameObjectImg, id, IB_AI3_right,IMG_3_Width, IMG_3_Height;贴图句柄2此处需修改！！！！图像并未设置完！！！
            .elseif eax == IB_AI3_right   ;贴图句柄4
                invoke  ChangeGameObjectImg, id, IB_AI3_right_down,IMG_3_Width, IMG_3_Height;贴图句柄2此处需修改！！！！图像并未设置完！！！
            .elseif eax == IB_AI3_right_down  ;贴图句柄2
                invoke  ChangeGameObjectImg, id, IB_AI3_right_down,IMG_3_Width, IMG_3_Height;贴图句柄2此处需修改！！！！图像并未设置完！！！
            .endif
        .endif

        invoke GetAIObject,id
        push time
        pop [eax+12]  ;更新changetime 使得changetime上一次随即改变姿态的时刻改变为此时
       ;否则changetime不变
    .endif
 ;////////////////////////////////////////////////////////////0
    mov ebx,time
    invoke GetAIObject,id
    .if aikind == ai_fish_kind3  ;此时为aifish禁止上游时间段 检查vy 使其一直小于0
        .if bantime == 0
            mov [eax+28],ebx ;首次进入到禁止时间段后将bantime初始化
        .endif
            PUSH [eax+28]
            pop bantime
            sub ebx,bantime
            invoke GetAIObject,id
            .if  velocityY < 0
                neg velocityY
            .endif
            .if ebx > 1000  ;!!此处可修改！！！当大于bantime3s时，禁止上/下游解除  根据x的方向来判断aifish原本的类型
                .if velocityX> 0
                    push ai_fish_kind1
                    pop [eax+36]
                .else
                    push ai_fish_kind2
                    pop [eax+36]
                .endif
            push 0
            pop [eax+28]
             ;将bantime为0
            .endif
    .elseif aikind== ai_fish_kind4  ;此时为aifish禁止下游时间段 检查vy 使其一直大于0
        .if bantime == 0
            mov [eax+28],ebx ;首次进入到禁止时间段后将bantime初始化
        .endif
        sub ebx,bantime
        .if  velocityY > 0
          neg velocityY
        .endif
        .if ebx > 1000  ;!!此处可修改！！！当大于bantime时，禁止上/下游解除  根据x的方向来判断aifish原本的类型
           .if velocityX> 0
                push ai_fish_kind1
                pop [eax+36]
            .else
                push ai_fish_kind2
                pop [eax+36]
            .endif
                push 0
                pop [eax+28] ;将bantime为0
        .endif
    .endif
     ;////////////////////////////////////////////////////////////
    invoke GetAIObject,id
    push velocityY
    pop WORD PTR [eax+10]
    invoke CalDisplacementByVelocity, velocityX, deltatime
    mov disX, eax
    invoke CalDisplacementByVelocity, velocityY, deltatime
    mov disY, eax
    invoke TranslateGameObject, id, disX, disY
    ret
MoveAIFish endp

;AI鱼碰撞应对策略
AI_DealWithCollsion proc cID: DWORD,myID:DWORD  ;撞到左右墙时更改x速度 与类型，撞到上下墙时更改类型，遇到此类型 movefish函数将处理，使其y方向锁定为一个固定方向
       LOCAL mygameobjectPTR:DWORD
       
       LOCAL myaikind:DWORD
       LOCAL myvelocityX :DWORD
       LOCAL myvelocityY :DWORD
       
       LOCAL myLevel:DWORD
       LOCAL cLevel:DWORD
       LOCAL myExp:DWORD
       LOCAL cExp:DWORD

       LOCAL cKind :DWORD

       invoke GetGameObject, cID
       
       .if eax == NULL
         ret
        .endif

       push [eax+4]
       pop cKind

       invoke GetAIObject,myID
       .if eax == NULL
         ret
         .endif
       push [eax+36]
       pop myaikind
        
     
       push [eax+4]
       pop myLevel
      
       .if cKind == WallLeftKind ;此处代表碰到左边界
           .if myaikind != ai_fish_kind5
                push ai_fish_kind1
                pop [eax+36]
                neg SWORD PTR[eax+8] ;将鱼velocityX 改为相反数
                invoke GetGameObject, myID
                .IF myLevel == 1
                    push IB_AI1_right_up
                    pop [eax+16]
                .ELSEIF myLevel == 2
                    push IB_AI2_right_up
                    pop [eax+16]
                .ELSEIF myLevel == 3
                    push IB_AI3_right_up
                    pop [eax+16]
                .ENDIF
           .endif
       .elseif cKind== WallRightKind ;此处代表碰到右边界
           .if myaikind != ai_fish_kind6
            push ai_fish_kind2
               pop [eax+36]
             neg SWORD PTR[eax+8] ;将鱼velocityX 改为相反数
              invoke GetGameObject, myID
                .IF myLevel == 1
                    push IB_AI1_left_up
                    pop [eax+16]
                .ELSEIF myLevel == 2
                    push IB_AI2_left_up
                    pop [eax+16]
                .ELSEIF myLevel == 3
                    push IB_AI3_left_up
                    pop [eax+16]
                .ENDIF
           .endif
       .elseif cKind== WallUpKind;此处代表碰到上边界
          push ai_fish_kind3
          pop [eax+36]  ;注意 此处kind3不代表以后将一直向下游 只是在一定时间周期期间将不再向上游
         ;关于对于kind3情况的处理 在MoveAIFish函数中
       .elseif cKind==WallDownKind;此处代表碰到上边界
          push ai_fish_kind4
          pop [eax+36];注意 此处kind4不代表以后将一直向上游 只是在一定时间周期期间将不再向下游
         ;关于对于kind4情况的处理 在MoveAIFish函数中
       .endif

     ret
AI_DealWithCollsion endp

;----------------------------------------------GameFunction(Player)---------------------------------------
ChangeV proc dir:sword
    ;暂定为1234上下左右,上正下负，左正右负
    local detla_v:sword
    local forceX : sword
    local forceY : sword

    xor eax, eax

    mov ax,player.a
    mov detla_v,ax

    mov ax,player.vx
    mov bx,player.vy

    .if dir == 2 &&  [PlayerDirFlag+4] ==0                           
        mov [PlayerDirFlag+0], 0
        add bx,detla_v
    .elseif dir == 1 &&  [PlayerDirFlag+0] ==0
        mov [PlayerDirFlag+4], 0
        sub bx,detla_v
    .elseif dir == 4 &&  [PlayerDirFlag+12] ==0
        mov [PlayerDirFlag+8], 0
        add ax,detla_v
    .elseif dir == 3 &&  [PlayerDirFlag+8] ==0
        mov [PlayerDirFlag+12], 0
        sub ax,detla_v
    .endif


    .if ax >= player.v_max_xz
        mov ax,player.v_max_xz
    .ENDIF
    .if ax <= player.v_max_xf
        mov ax,player.v_max_xf
    .ENDIF
    .if bx >= player.v_max_yz
        mov bx,player.v_max_yz
    .ENDIF
    .if bx <= player.v_max_yf
        mov bx,player.v_max_yf
    .ENDIF
    mov player.vx, ax
    mov player.vy, bx

    mov forceX, 0
    .IF player.vx > 0
        mov forceX, -1
    .ELSEIF player.vx < 0
        mov forceX, 1
    .ENDIF

    mov forceY, 0
    .IF player.vy > 0
        mov forceY, -1
    .ELSEIF player.vy < 0
        mov forceY,  1
    .ENDIF

    

    mov ax, forceX
    add player.vx, ax
    mov ax, forceY
    add player.vy, ax

    mov MesDir, 0
    ret
ChangeV endp

UpdatePlayerPlace PROC detla_t:WORD
    LOCAL disX : SDWORD
    LOCAL disY : SDWORD
    invoke CalDisplacementByVelocity, player.vx, detla_t
    mov disX, eax
    invoke CalDisplacementByVelocity, player.vy, detla_t
    mov disY, eax
    invoke TranslateGameObject, bkqID, disX, disY
   ret
UpdatePlayerPlace endp

GetDir proc uMsg:UINT, wParam:WPARAM
     .IF wParam==VK_UP&&uMsg==WM_KEYDOWN
        mov MesDir,1
        mov PressFlag,1
    .ELSEIF wParam==VK_DOWN&&uMsg==WM_KEYDOWN
        mov MesDir,2
        mov PressFlag,1
    .ELSEIF wParam==VK_LEFT&&uMsg==WM_KEYDOWN
        mov MesDir,3
        mov PressFlag,1
    .ELSEIF wParam==VK_RIGHT&&uMsg==WM_KEYDOWN
        mov MesDir,4
        mov PressFlag,1
    .ELSE
        mov MesDir,0
    .ENDIF
    ret
GetDir endp

Player_DealWithCollsion proc cID:DWORD,myID:DWORD
    LOCAL cKind : DWORD

    invoke GetGameObject, cID
    mov ebx, eax
    push [ebx+4]
    pop cKind
    
    .if cKind==4              ;碰上边界
        mov PlayerDirFlag, 1
        mov player.vy,0
    .elseif cKind==5          ;碰下边界
        mov [PlayerDirFlag+4], 1
        mov player.vy,0
    .elseif cKind==2          ;碰左边界
        mov [PlayerDirFlag+8], 1
        mov player.vx,0
    .elseif cKind==3          ;碰右边界
        mov [PlayerDirFlag+12], 1
        mov player.vx,0
    .else                   ;碰鱼
        invoke PlayerCollsionFish,cID
    .endif
    ret
Player_DealWithCollsion endp

PlayerCollsionFish proc cID:DWORD
    LOCAL coffset:DWORD
    LOCAL fishgrade :DWORD
    LOCAL fishexp:DWORD

    invoke GetAIObject, cID    ;给ID返回鱼结构体的偏倚地址
    .IF eax == NULL
        ret
    .ENDIF
    mov coffset,eax
    ;需要给fishexp、fishgrade赋值

    mov ebx, coffset
    push [ebx+4]
    pop  DWORD PTR fishgrade
    push [ebx+24]
    pop  fishexp
    mov eax, fishgrade
    ;判断等级和经验值
    .if player.grade < ax
        invoke GameOver
    .else
        invoke SetTimer, mainHwnd, IDT_CreatFish_Begin, 1000, NULL
        inc IDT_CreatFish_Begin

        invoke Delete_ai, cID
        invoke PlaySound, offset BGM_eat_PATH, NULL, SND_ASYNC
        
        mov eax, fishexp
        add score, eax

        mov eax,fishexp
        xor ebx,ebx
        mov bx,player.exp
        add eax,ebx
        mov player.exp,ax

        mov ax,player.max_exp
        .if player.exp >= ax
            invoke LevelUp
        .endif
    .endif
    ret
PlayerCollsionFish endp

LevelUp proc
    .IF player.grade < 3
        .if player.grade ==1
            mov player.max_exp,play_maxexp_2
            mov curMaxExp, play_maxexp_2
        .elseif player.grade ==2
            mov player.max_exp, play_maxexp_3 
            mov curMaxExp, play_maxexp_3
        .endif
        inc player.grade
        mov player.exp,0
    .ELSE
        .IF end_flag==0
            mov end_flag,1
            mov timer, END_WIN_TIMER
            invoke SetTimer, mainHwnd, IDT_PlayerWin, END_WIN_TIMER, NULL
        .ENDIF
    .ENDIF
    ret
LevelUp endp    

ChangePlayerPictureDir PROC
    LOCAL num:DWORD
    LOCAL himg:HBITMAP

    mov num, 0
    inc player_picture_times 
    .if player_picture_times >= 3
        sub player_picture_times, 3
    .endif

    mov eax, num
    mov ebx, player_picture_times
    add eax,ebx
    mov num,eax

     .if player.vx > -1
        add num,0
    .else 
        add num,3       ;待改
    .ENDIF

    .if player.grade == 1
        lea eax, IB_player1_right_up
    .elseif player.grade == 2
        lea eax,IB_player2_right_up
    .elseif player.grade == 3
        lea eax,IB_player3_right_up
    .endif
    mov ebx,num
    mov ecx,[eax][ebx * 4]

    mov himg,ecx
    
    .if player.grade == 1
        invoke ChangeGameObjectImg,bkqID, himg,IMG_1_Width,IMG_1_Height
    .elseif player.grade == 2
        invoke ChangeGameObjectImg,bkqID, himg,IMG_2_Width,IMG_2_Height
    .elseif player.grade == 3
        invoke ChangeGameObjectImg,bkqID, himg,IMG_3_Width,IMG_3_Height
    .endif
    ret
ChangePlayerPictureDir ENDP

;-----------------------------------------main-----------------------------
main:   
    invoke GetModuleHandle, NULL    ;获取应用程序句柄
    mov hInstance, eax
    invoke WinMain, hInstance, NULL, NULL, SW_SHOWDEFAULT
    invoke ExitProcess, eax ;退出程序
ret
end main